package com.fp.m7.model;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "follows")
@NamedQuery(
        name = "findFollowers",
        query = "from Follow f where f.follower = :follower and f.followed = :followed and f.auditDD is null order by f.auditCD")
public class Follow extends EntityBase {
    private static final long serialVersionUID = 8489803917505881539L;

    private Account follower;
    private Account followed;

    protected Date auditDD; // if not null means that this follow subscription is over

    public Follow() {
    }

    public Follow(Account follower, Account followed) {
        this.follower = follower;
        this.followed = followed;
    }

    @ManyToOne(optional = false)
    @JoinColumn(name = "follower_account_fk")
    public Account getFollower() {
        return follower;
    }

    public void setFollower(Account follower) {
        this.follower = follower;
    }

    @ManyToOne(optional = false)
    @JoinColumn(name = "followed_account_fk")
    public Account getFollowed() {
        return followed;
    }

    public void setFollowed(Account followed) {
        this.followed = followed;
    }

    @Temporal(TemporalType.TIMESTAMP)
    public Date getAuditDD() {
        return auditDD;
    }

    public void setAuditDD(Date auditDD) {
        this.auditDD = auditDD;
    }

    @Override
    public String toString() {
        return new StringBuilder("Follow [id=").append(id) //
                .append("; follower=").append(follower) //
                .append("; followed=").append(followed) //
                .append("; auditCD=").append(auditCD) //
                .append("; auditDD=").append(auditDD).append("]").toString();
    }

}
